package demo.messaging.client.ui;

import demo.messaging.client.core.ApplicationContext;
import demo.messaging.client.core.ClientManager;
import demo.messaging.client.core.IMessageEventListener;
import demo.messaging.client.core.MessageEvent;
import demo.messaging.client.core.MessageEvent.EnumMessageEventType;
import demo.util_ui.client.ui.SimpleDialog;

public class OutgoingInvitationUI extends SimpleDialog implements
		IMessageEventListener {

	public OutgoingInvitationUI() {
		super("Cancel invitation");
	}

	@Override
	protected void onCloseButtonClicked() {
		ClientManager.getClientManager().sendCancelMessageToGuest();
	}

	@Override
	public void onMessageEvent(final MessageEvent event) {
		if (event.getType() == EnumMessageEventType.invitationSent) {

			resetContent("Sending Invitation...",
					"Please wait for the response of "
							+ ClientManager.getClientManager()
									.getCurrentGuest(), null);
			this.center();

		} else if (event.getType() == EnumMessageEventType.acceptanceReceived) {

			hide();

		} else if (this.isShowing()
				&& event.getType() == EnumMessageEventType.cancelReceived) {
			hide();
			((SimpleDialog) ApplicationContext.getBean("infoDialog")).showInfo(
					"Notification", event.getMessage().getSender()
							+ " has declined your invitation.");
		}

	}
}
